<template>
  <div class="desc-list-wrap">
    <div class="left">
      <description title="">
        <description-item label="合同编号"
                          :value="waybillDetails.contractNo" />
        <description-item v-if="!!waybillDetails.customer"
                          :label="`${diffType === 10 ? '发货方名称' : '承运方名称'}`"
                          :value="diffType === 10 ? waybillDetails.customer.showCustomerName : waybillDetails.carrier && waybillDetails.carrier.carrierName"
                          :icon-name="iconName"
                          :content="content" />
        <description-item v-if="!!waybillDetails.carrier"
                          label="自营司机"
                          :value="waybillDetails.carrier.driverName" />
        <description-item v-if="!!waybillDetails.dispatchBy"
                          label="制单人"
                          :value="waybillDetails.dispatchBy.name" />
        <description-item label="创建时间"
                          :value="waybillDetails.createAt" />
        <description-item label="单据编号"
                          :value="waybillDetails.no" />
      </description>
    </div>
    <div class="right">
      <description title="">
        <description-item label="合单"
                          :value="`${waybillDetails.orderSubQuantity}单`"
                          :span="8" />
        <description-item label="提送次数"
                          :value="someSubmitted"
                          :span="8" />
        <description-item label="物品总价值"
                          :value="waybillDetails.totalValue ? thousandDigit(waybillDetails.totalValue, 2) : 0"
                          :span="8" />
        <description-item label="总数量"
                          :value="waybillDetails.totalQuantity"
                          :span="8" />
        <description-item label="总重量(公斤)"
                          :value="waybillDetails.calculateWeight"
                          :span="8" />
        <description-item label="总体积(方)"
                          :value="waybillDetails.calculateVolume"
                          :span="8" />
        <description-item label="发货时间"
                          :value="waybillDetails.fromTime"
                          :span="8" />
        <description-item label="收货时间"
                          :value="waybillDetails.toTime"
                          :span="8" />
        <description-item label="备注信息"
                          :value="waybillDetails.desc" />
      </description>
    </div>
  </div>
</template>

<script>
import Description from "./Description";
import DescriptionItem from "./DescriptionItem";
import { returnThousandDigit } from "@/libs/util.js";
export default {
  name: "DescList",
  components: { Description, DescriptionItem },
  props: {
    waybillDetails: {
      type: Object,
      default: () => { }
    }
  },
  computed: {
    diffType () {
      let diffType = null
      if (this.waybillDetails?.waybills?.length) {
        diffType = this.waybillDetails?.waybills[0]?.waybillType;
      }
      return diffType
    },
    someSubmitted () {
      let lift = null; let give = null
      if (this.waybillDetails?.distinctFromAddress?.length) {
        lift = `${this.waybillDetails?.distinctFromAddress?.length}提`;
      }
      if (this.waybillDetails?.distinctToAddress?.length) {
        give = `${this.waybillDetails?.distinctToAddress?.length}送`;
      }
      return lift + give;
    },
    content () {
      const { customer, carrier } = this.waybillDetails
      if (this.diffType === 10) {
        switch (customer?.showCustomerType) {
          case 0:
            return '线下';
          case 1:
            return '线上';
          default:
            return '';
        }
      } else {
        if (carrier?.carrierType === 0) {
          return '线下'
        }
        if (carrier?.carrierType === 1 && carrier?.carrierExtraType === 0) {
          return '线上'
        }
      }
      return '';
    },
    iconName () {
      const { customer, carrier } = this.waybillDetails
      if (this.diffType === 10) {
        switch (customer?.showCustomerType) {
          case 0:
            return 'xianxia';
          case 1:
            return 'xianshang';
          default:
            return '';
        }
      } else {
        if (carrier?.carrierType === 0) {
          return 'xianxia'
        }
        if (carrier?.carrierType === 1 && carrier?.carrierExtraType === 0) {
          return 'xianshang'
        }
      }
      return '';
    }
  },
  methods: {
    thousandDigit (value, digit) {
      return returnThousandDigit(value, digit)
    },
  }
};
</script>

<style scoped lang="scss">
.iconClass {
  width: 14px;
  height: 14px;
}
.desc-list-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 30px 0px 30px;
}
.left {
  width: 30%;
  border-right: 1px #ebebeb solid;
  // margin-left: 20px;
  // margin-right: 20px;
}
.right {
  width: 70%;
  // margin-left: 20px;
  // margin-right: 20px;
}
</style>
